/*© 2010-2011 mOcean Mobile. A subsidiary of Mojiva, Inc. All Rights Reserved.*/
package com.adserver.adview.examples;

import com.adserver.adview.AdServerException;
import com.adserver.adview.AdServerView;
import com.adserver.adview.Logger;
import com.adserver.adview.interfaces.OnAdNavigateBanner;
import com.adserver.adview.interfaces.OnAdWebViewClosing;

import javax.swing.*;
import java.util.logging.Level;

class AdServerSample5 extends AdServerViewSampleRunner {
    private static final int width = 320;
    private static final int height = 460;

    @Override
    protected void initAdServerView() throws AdServerException {
        // Interstitial ad
        adServerView = new AdServerView("8061", "16112");
//        adServerView.setMinSizeX(width);
//        adServerView.setMinSizeY(height);
//        adServerView.setMaxSizeX(width);
//        adServerView.setMaxSizeY(height);
        adServerView.setUpdateTime(4);
        //adServerView.setDefaultImage("images/mOcean.jpg");
        adServerView.setInternalBrowser(true);
        adServerView.setAdNavigateBanner(new UserAdDownload());
        adServerView.setAdWebViewClosing(new UserAdWebViewClosing());
        adServerView.setTextColor("00FF00");
        adServerView.setBackgroundColor("FF0000");
        adServerView.setKeywords("keywords=music,games");
    }

    class UserAdDownload implements OnAdNavigateBanner {
        public boolean click(String url) {
            String msg = "UserAdWebViewClosing click from com.adserver.adview.examples.AdServerSample5" + "\n";
            Logger.getInstance().logText(Level.INFO, msg);
            textArea.append(msg);

            int n = JOptionPane.showConfirmDialog(null,
                    "Would you like to process url by yourself (yes) or to use internal browser for URL (no): ",
                    url, JOptionPane.YES_NO_OPTION);

            return n == JOptionPane.NO_OPTION;
        }
    }

    class UserAdWebViewClosing implements OnAdWebViewClosing {
        public void process(String url) {
            String msg = "UserAdWebViewClosing click from com.adserver.adview.examples.AdServerSample5: " + url;
            Logger.getInstance().logText(Level.INFO, msg);
        }
    }

    public static void main(String args[]) throws AdServerException {
        AdServerSample5 adServerSample = new AdServerSample5();
        adServerSample.initAdServerView();
        adServerSample.runSample();
    }
}